#include<iostream>
#include<pthread.h>
#include<string>
#include<queue>
#include<stdio.h>
#include<unistd.h>
using namespace std;
int flag =1;
pthread_mutex_t mutex;
pthread_cond_t condt;
void* Print(void* args)
{
	while(1)
	{
	pthread_mutex_lock(&mutex);
	sleep(1);
	const string name =static_cast<const char*>(args);
	if((flag&&name=="B"||(!flag&&name=="A")))
		pthread_cond_wait(&condt,&mutex);
	cout<<"我是:"<<name<<endl;
	flag =!flag;
	pthread_cond_signal(&condt);
	pthread_mutex_unlock(&mutex);
	}
	return nullptr;
}
int main()
{
	pthread_t pa,pb;
	char namea[]="A";
	char nameb[]="B";
	pthread_mutex_init(&mutex,nullptr);
	pthread_cond_init(&condt,nullptr);
	pthread_create(&pb,nullptr,Print,(void*)nameb);
	pthread_create(&pa,nullptr,Print,(void*)namea);
	pthread_join(pa,nullptr);
	pthread_join(pb,nullptr);
	return 0;
}
